<?php
/***
	pms模型。
**/
class Pdms_pms_model extends CI_Model {
	
	public function __construct() {
		$this->load->database();
	}
	
	//新增
	public function create() {
	
	$type = $this->input->post('type');
	$standard = $this->input->post('standard');
	$subtype = $this->input->post('subtype');
	$contype = $this->input->post('contype');
	$classthk = $this->input->post('classthk');
	
	$data = array(
			'project_id' => $this->input->post('project_id'),
			'pipe_class' => $this->input->post('pipe_class'),
			'head_code' => $standard.$type.$subtype,
			'shap_code' => $standard.$type.$subtype.$contype.$classthk,
			'material_code' => $this->input->post('material'),
			'min_dn' => $this->input->post('min_dn'),
			'max_dn' => $this->input->post('max_dn')
		);
		
		return $this->db->insert('pms', $data);
	}
	
	//有project_id和pipe_class查询
	public function get_by_project_class ($project_id, $pipe_class) {
		$sql = "select pms.id, pms.min_dn, pms.max_dn, pms.project_id, pms.pipe_class, materialcode.des as material, shapcodes.des as shap from pms 
		inner join materialcode on pms.material_code = materialcode.code 
		inner join shapcodes on pms.shap_code = shapcodes.code 
		where project_id = '".$project_id."' and pipe_class = '".$pipe_class."' ORDER BY pms.shap_code";
		$query = $this->db->query($sql);
		return $query->result_array();
	}
	
	//按project_id查询class
	public function get_class_by_project($project_id) {
		
		$sql = "select DISTINCT pipe_class from pms where project_id = '".$project_id."'";
		$query = $this->db->query($sql);
		//$query = $this->db->get_where('pms', array('project_id' => $project_id));
		return $query->result_array();
	}
	
	//删除
	public function del ($id) {
		$this->db->delete('pms', array('id' => $id));
		
	}
	
	
	
	//以下没有修改，不能直接使用
	//查询所有
	public function get_all() {
		
		$query = $this->db->get('type');
		return $query->result_array();
	}
	
	//通过code查询
	public function get_by_code($code) {
		$query = $this->db->get_where('type', array('code' => $code));
		return $query->row_array();
	}
	
	
	//修改
	public function edit ($code) {
		$data = array(
			'des' => $this->input->post('des'),			
		);
		
		$this->db->where('code', $code);
		$this->db->update('type', $data);
	}
	
	
	
}